import { http } from './httpServer'
import config from '../config'
import constants from '../constants'
import store from '../store'

import * as proxyModule from './proxyModule'

// 获取客户信息
export function getCustomerInfo(customerId) {
	return http.get(`/mall/app/customer/v1/customer/${customerId}`).exec()
}

// 获取收货地址
export function getAddressList(){
    return http.get(`/mall/app/address/v1/addresses`).withLoading().exec()
}

/**
 * @description: 新增收货地址
 * @param {type} 
 * @return: 
 */
export function addAddress(data){
    return http.post(`/mall/app/address/v1/addresses`,data).withLoading().exec()
}

/**
 * @description: 编辑收货地址
 * @param {type} 
 * @return: 
 */
export function editAddress(data){
    return http.post(`/mall/app/address/v1/address`,data).withLoading().exec()
}

/**
 * @description: 删除收货地址
 * @param {type} 
 * @return: 
 */
export function delAddress(data){
    return http.post(`/mall/app/address/v1/address/del`,data).withLoading().exec()
}

/**
 * @description: 查询商家的类目列表
 * @param {type} 
 * @return: 
 */
export function GetCateList(data=store.state.merchantId){
    return http.get(`/mall/app/product/v1/categories/${data}`).exec()
}

/**
 * @description: 根据类别分页查询商品列表
 * @param {type} 
 * @return: 
 */
export function GetProductsByCate(data){
    return http.get(`/mall/app/product/v1/products/pagenation`, data).withLoading().exec()
}

/**
 * @description: 根据产品编码查询产品详细
 * @param {type} 
 * @return: 
 */
export function GetProductDetail(params){
    return http.get(`/mall/app/product/v1/product/${params}`).withLoading().exec()
}

/**
 * @description: 新增个人收藏
 * @param {type} 
 * @return: 
 */
export function addFavoriate(data){
    return http.post(`/mall/app/customer/v1/favoriate`,data).withLoading().exec()
}

/**
 * @description: 查询我的收藏
 * @param {type} 
 * @return: 
 */
export function getFavoriateList(data){
    return http.get(`/mall/app/customer/v1/favoriate/${data}`).withLoading().exec()
}

/**
 * @description: 移除我的收藏
 * @param {type} 
 * @return: 
 */
export function removeFavoriate(data){
    return http.post(`/mall/app/customer/v1/favoriates/favoriate`,data).withLoading().exec()
}

/**
 * @description: 创建订单 提交订单？
 * @param {type} 
 * @return: 
 */
export function creatOrder(data){
   return http.post(`/mall/app/order/v1/`,data).exec()
}

/**
 * @description: 登录接口
 * @param {type} 
 * @return: 
 */
export function getToken(data){
    return http.post(`/mall/app/wx/v1/token`,data).exec()
}

export function login(data) {
	return http.post(`/mall/app/customer/v1/freshCustomerWxInfo`, data).withLoading().exec()
}

/**
 * @description: 查询个人订单
 * @param {type} 
 * @return: 
 */
export function GetOrderList(data){
    return http.get(`/mall/app/order/v1/orders`,data).exec()
}

/**
 * 提醒卖家发货
 * */
export function RemindDelivery(orderId) {
	return http.post('/mall/app/order/v1/remind', orderId).exec();
}

/**
 * 确认收货
 * @param {Object} orderId
 */
export function ConfirmGoods(orderId) {
	return http.post('/mall/app/order/v1/confirm', orderId).exec();
}

export function RequestRefund(orderId) {
	return http.post('/mall/app/order/v1/refund/apply', orderId).exec();
}

export function CancelRefund(orderId) {
	return http.post('/mall/app/order/v1/refund/cancel', {
		contactor: '',
		mobileNo: '',
		orderId,
		reason: ''
	}).exec();
}

/**
 * @description: 查询banner，根据商家ID
 * @param {type} 
 * @return: 
 */
export function GetBannerList(merchantId = store.state.merchantId){
    return http.get(`/mall/app/banners/v1/${merchantId}`).withLoading().exec()
}

export function pay(data){
	return http.post(`/mall/app/pay/v1/order`,data).withLoading().exec()
}

export default {
	getCustomerInfo,
    getAddressList,
    addAddress,
    editAddress,
    delAddress,
    GetCateList,
    GetProductsByCate,
    GetProductDetail,
    addFavoriate,
    getFavoriateList,
    removeFavoriate,
    creatOrder,
    login,
	getToken,
    GetOrderList,
    GetBannerList,
    pay,
	RemindDelivery,
	ConfirmGoods,
	RequestRefund,
	CancelRefund,
    /**
     * @description: 获取评论列表
     * @param {type} 
     * @return: 
     */
    GetCommentList({ productId, pageNum }){
        return http.get(`/mall/app/product/v1/comments?productId=${productId}&pageNum=${pageNum}&pageSize=20`).withLoading().exec()
    },
    UploadFileUrl: `${config.host}/mall/file/v1/`,

    /**
     * @description: 增加评论
     * @param {type} 
     * @return: 
     */    
    AddComment(data){
        return http.post(`/mall/app/order/v1/comment`, data).withLoading().exec()
    },
	
	/**
	 * @description: 获取物流列表
	 * @param {type} 
	 * @return: 
	 */  
	GetExpressList(customerId=store.state.customerId){
		return http.get(`/mall/app/delivery/v1/deliveries`).withLoading().exec()
    },

    /**
     * @description: 维护到购物车
     * @param {type} 
     * @return: 
     */    
    SetCartList(data){
        return http.post(`/mall/app/cart/v1/cart` ,Object.assign(data,{ customerId: store.state.customerId })).withLoading().exec()
    },

    /**
     * @description: 查询购物车
     * @param {type} 
     * @return: 
     */   
    GetCartList(customerId = store.state.customerId){
        return http.get(`/mall/app/cart/v1/carts`).withLoading().exec()
    },


    /**
     * @description: 删除购物车记录
     * @param {type} 
     * @return: 
     */    
    DelCartList(data){
        return http.post(`/mall/app/cart/v1/cart/clear` ,Object.assign(data,{ customerId: store.state.customerId })).withLoading().exec()
    },

    /**
     * @description: 更新订单状态
     * @param {type} 
     * @return: 
     */
    UpdateOrderState(data){
        return http.post(`/mall/app/order/v1/order`, data).withLoading().exec()
    },

    /**
     * @description: 显示首页类别产品
     * @param {type} 
     * @return: 
     */
    GetProductListByHome(params){
        return http.get(`/mall/app/product/v1/products/firstpage`, params).exec()
    },

    /**
     * @description: 根据订单号查询单一订单
     * @param {type} 
     * @return: 
     */    
    GetDetailByOrderId(params){
        return http.get(`/mall/app/order/v1/items/${params}`).exec()
    },

    /**
     * @description: 更新用户订单
     * @param {type} 
     * @return: 
     */   
    UpdateUserOrder(data){
        return http.post(`/mall/app/order/v1/order`,data).withLoading().exec()
    },
	
	/**
	 * @description 根据商品ID, 商家ID 查询对应的优惠券
	 * @param {Object} data
	 */
	GetCouponsByProduct(productId, merchantId, customerId) {
		return http.get(`/mall/app/product/v1/coupon/product/list?productId=${productId}&merchantId=${merchantId}`).exec()
	},
	
	/**
	 * @description 领取优惠券
	 * @param {Object} params
	 */
	ReceiveCoupon(params) {
		return http.post('/mall/app/coupons/v1/coupon/get', params).exec()
	},
	
	GetMyCoupons(merchantId, customerId) {
		return http.get(`/mall/app/coupons/v1/coupon/customer/list?merchantId=${merchantId}&customerId=${customerId}`).exec()
	},
	/**
	 * 查询订单中能用的优惠券, 及金额等信息
	 */
	GetOrderCoupons(merchantId, customerId, orderItems) {
		return http.post(`/mall/app/coupons/v1/coupon/order/list?merchantId=${merchantId}&customerId=${customerId}`, orderItems).exec()
	},
	
	/**
	 * 查询各类订单的数量
	 */
	GetOrderCounts() {
		return http.get(`/mall/app/order/v1/status/count`).exec()
	},
	
	GetCommentCounts() {
		return http.get('/mall/app/order/v1/comments/number').exec()
	},
	
	getCommentOrders({
		isComment,
		customerId,
		merchantId,
		pageNum,
		pageSize
	}) {
		return http.get(`/mall/app/order/v1/comments?isComment=${isComment}&customerId=${customerId}&merchantId=${merchantId}&pageNum=${pageNum}&pageSize=${pageSize}`).exec()
	},
	
	// 代理模块接口
	...proxyModule
}